#include <iostream>
using namespace std;

/*
    继承之后：构造函数的调用规则
       1.先调用父类的无参构造，再调用子类自己的构造(先父后子)
         默认情况下，父类构造函数是先调用无参构造函数
*/

class Animal
{
public:
    Animal()
    {
        cout << "Animal()" << endl;
    }
    void setAge(int a)
    {
        age = a;
    }
    Animal(int a)
    {
        cout << "Animal(int a)" << endl;
    }
    void showAge()
    {
        cout << " age:" << age << endl;
    }

private:
    int age;
};

class Cat : public Animal
{
public:
    Cat()
    {
        cout << "Cat()" << endl;
    }
    Cat(string name, int age)
    {
        this->name = name;
        setAge(age);
        cout << "Cat(string name, int age)" << endl;
    }

    void showName()
    {
        cout << " name:" << name << endl;
    }

private:
    string name;
};

int main()
{
    Cat cat;
    cout << "------------------------" << endl;
    Cat cat1("Tom", 10);
    cat1.showName();
    cat1.showAge();
    return 0;
}